var itemType='00';

jQuery(document).ready(function() {
	
	init();
					
});		

function init(){	
	//获取主键
	var pa=location.search.substring(1).replace('param=','').split("-");
	var pk = pa[0];
	var itemno = pa[1];
	var type = getQueryString('type'); 
	
	if(pk != ''){
		$.ajax({
			type:"get",
			url : projectPath + "declare/getguideinfo.do",
			data :  {"sgid":pk},
			dataType : "json",
			contentType : "application/json",
			success : function(data) {
				var content=data.datas.content;
//				img=img.substring(img.indexOf("<img"),img.length);
//				img=img.substring(0,img.indexOf(">")+1);
				$("#info").html(content);
				var tableid = data.datas.tableid;
				var styletext =data.datas.styletext;
				initTable(tableid);
				initTable1(styletext);
			}
		});
	}
	else{
		$("#info").html('');
	}
	
	if(type == 'table'){
		$("#tab-table").click();
	}else if(type == 'txt'){
		$("#tab-txt").click();
	}
}


function initTable(tableid){	
	$('#dataTable').bootstrapTable({
		method: 'post',
	    url: basePath() + 'declare/guidetable.do',
	    pagination: true, //分页
	    dataType: "json",
        contentType: "application/json",
        pageList: [10, 20, 50, 100],  //可供选择的每页的行数（*）
        striped: true,      //是否显示行间隔色
        sidePagination: "server",
        ////查询参数,每次调用是会带上这个参数，可自定义                         
        queryParams:function(params) {
            return {
                	pageNum: params.offset / params.limit + 1,
                	pageSize: params.limit,
                	fileid:tableid
                };
        },
	    columns: [{  
            field : 'number',  
            title : '序号',  
            align : 'center',
            width : '80px',
            formatter : function(value, row, index) { 
// 		                return index + 1;  
                var page = $('#dataTable').bootstrapTable("getPage");  
                return page.pageSize * (page.pageNumber - 1) + index + 1;  
            }         
	    }, {
	    	 field: 'key',
	    	 visible : false
	    }, {
	        field: 'caption',
	        title: '表格名',
	        align : 'center',
	        formatter : function(value, row, index) { 
	        	return [
	        		'<a href="/gahCSP/share/downFiles.do?filename='+ row.caption +'&fileid='+ row.key +'">' + row.caption + '</a>'
	        	].join('');
	        }
        }]
	});
}

function initTable1(styletext){	
	$('#txtTable').bootstrapTable({
		method: 'post',
	    url: basePath() + 'declare/guidetable1.do',
	    pagination: true, //分页
	    dataType: "json",
        contentType: "application/json",
        pageList: [10, 20, 50, 100],  //可供选择的每页的行数（*）
        striped: true,      //是否显示行间隔色
        sidePagination: "server",
        ////查询参数,每次调用是会带上这个参数，可自定义                         
        queryParams:function(params) {
            return {
                	pageNum: params.offset / params.limit + 1,
                	pageSize: params.limit,
                	fileid:styletext
                };
        },
	    columns: [{  
            field : 'number',  
            title : '序号',  
            align : 'center',
            width : '80px',
            formatter : function(value, row, index) { 
// 		                return index + 1;  
                var page = $('#dataTable').bootstrapTable("getPage");  
                return page.pageSize * (page.pageNumber - 1) + index + 1;  
            }         
	    }, {
	    	 field: 'key',
	    	 visible : false
	    }, {
	        field: 'caption',
	        title: '样例名',
	        align : 'center',
	        formatter : function(value, row, index) { 
	        	return [
	        		'<a href="/gahCSP/share/downFiles.do?filename='+ row.caption +'&fileid='+ row.key +'">' + row.caption + '</a>'
	        	].join('');
	        }
        }]
	});
}
